package com.aube.interact.fighter;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.aube.interact.fighter.model.GameConfig;
import com.huyn.baseframework.ImageLoader;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by huyaonan on 16/11/23.
 */
public class GamePrizeLayout extends LinearLayout {

    private ImageView mImg;
    private GamePrizeProgress mProgress;
    private GamePrizeTextView mTxt;
    private AtomicBoolean mReadyForDraw = new AtomicBoolean(false);

    public GamePrizeLayout(Context context) {
        this(context, null);
    }

    public GamePrizeLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GamePrizeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        LayoutInflater.from(context).inflate(R.layout.aube_intera_game_prize_layout, this, true);

        mImg = (ImageView) findViewById(R.id.game_prize_logo);
        mProgress = (GamePrizeProgress) findViewById(R.id.game_prize_progress);
        mTxt = (GamePrizeTextView) findViewById(R.id.game_prize_txt);
    }

    public void update(String url, float ratio, String txt) {
        mProgress.updateProgress(ratio);
        mTxt.setText(txt);
    }

    public void update(int current, int max) {
        mProgress.updateProgress(current*1f/max);
        mTxt.setText(current+"/"+max);

        mReadyForDraw.set(current >= max);
    }

    public void prepare(GameConfig config) {
        if(config == null)
            return;

        mProgress.updateProgress(0f);
        mTxt.setText("0/" + config.fragmentMaxNum);
//        ImageLoader.getInstance(getContext()).fillImage(mImg, config.normalFragmentPic);
//        ImageLoader.getInstance(getContext()).preloadBitmap(config.prizeFragmentPic, null);
    }

    public boolean isReady() {
//        return mReadyForDraw.get();
        return true;
    }

}
